import { getGameObjectById } from "../engine";
import { Behaviour } from "../engine/Behaviour";
import { TextRenderer } from "../engine/TextRenderer";
import { Transform } from "../engine/Transform";
import { number } from "../engine/validators/number";
import { BillSystem } from "./BillSystem";
import { dateStorageInUI } from "./dateStorageInUI";
import { Display } from "./Display";


export class DialogActive extends Behaviour {

    Order1="来一份经典原味的烤冷面！";
    Order2="老板，我要一个经典加肠烤冷面。";
    Order3="来份火辣辣烤冷面！";
    Order4="我要一个加鸡柳烤冷面。";
    Order5="我要一个烤冷面加培根。";
    Order6="原味的加蒜蓉酱！";
    Order7="没人不喜欢葱花吧！你说是不是！";
    Order8="原味的！我爱BJUT！";
    Order9="老板，最近想尝尝辣酱了~";
    Order10="老板，来一个豪华套餐！";

    Order_what=0;

    onStart() {
        let IsBuyFlag1=getGameObjectById('UI_button_money_ChilliSauce').getBehaviour(BillSystem).IsSold_ChilliSource;
        let IsBuyFlag2=getGameObjectById('UI_button_money_SunRong').getBehaviour(BillSystem).IsSold_SuanRong;
        let IsBuyFlag3=getGameObjectById('UI_button_money_Conghua').getBehaviour(BillSystem).IsSold_CongHua;
        let IsBuyFlag4=getGameObjectById('UI_button_money_Bacon').getBehaviour(BillSystem).IsSold_Bacon;
        let IsBuyFlag5=getGameObjectById('UI_button_money_Chicken').getBehaviour(BillSystem).IsSold_Chicken;
        let IsBuyFlag6=getGameObjectById('UI_button_money_BJUTBox').getBehaviour(BillSystem).IsSold_BJUTBox;

        let Order_Text:string;
        let i:number;
        let Currentday:number;
        //console.log(getGameObjectById('UI_dialog_requirement').getBehaviour(TextRenderer).text);          

        this.gameObject.onClick = () => {
         
             console.log(this.gameObject.id);
            if(this.gameObject.id=="UI_button_DialogActive"){
                Currentday=getGameObjectById('dateStorage').getBehaviour(dateStorageInUI).currentday;

                if(Currentday==1){
                    i=this.GetRandomNum(1,3);
                }else{
                    i=this.GetRandomNum(1,10);
                }
                   
                   this.SelectOrder(i);
                   
                getGameObjectById('UI_dialog_frame').getBehaviour(Display).IsActive=true;
                getGameObjectById('UI_dialog_requirement').getBehaviour(Display).IsActive=true;
                Order_Text=getGameObjectById('UI_dialog_requirement').getBehaviour(TextRenderer).text; 
                getGameObjectById('dateStorage').getBehaviour(dateStorageInUI).currentOrder=Order_Text;   
                
                switch(Order_Text){
                    //经典=酱+醋+糖+鸡蛋
                    case "来一份经典原味的烤冷面！":{
                        getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=false;
                        getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=false;
                        break;               
                    }
                    //加肠=酱+醋+糖+鸡蛋+肠
                    case "老板，我要一个经典加肠烤冷面。":{
                        getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=false;
                        getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=false;
                        break;               
                    }
                    //火辣辣=酱+醋+糖+鸡蛋+辣条
                    case "来份火辣辣烤冷面！":{
                        getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=true;
                        getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=false;
                        getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=false;
                        break;               
                    }
                    //加鸡柳=酱+醋+糖+鸡蛋+鸡柳
                    case "我要一个加鸡柳烤冷面。":{
                        if(IsBuyFlag5==false){
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=false;
                        }else{
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=false;
                        }               
                    }
                    //加培根=酱+醋+糖+鸡蛋+培根
                    case "我要一个烤冷面加培根。":{
                        if(IsBuyFlag4==false){
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=false;
                        }else{
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=false;
                        }               
                    }
                    //加蒜蓉酱=酱+醋+糖+鸡蛋+蒜蓉
                    case "原味的加蒜蓉酱！":{
                        if(IsBuyFlag2==false){
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=false;
                        }else{
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=false;
                        }               
                    }
                    //加葱花=酱+醋+糖+鸡蛋+葱花
                    case "没人不喜欢葱花吧！你说是不是！":{
                        if(IsBuyFlag3==false){
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=false;
                        }else{
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=false;
                        }               
                    }
                    //经典=酱+醋+糖+鸡蛋+【盒子】
                    case "原味的！我爱BJUT！":{
                        if(IsBuyFlag6==false){
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=false;
                        }else{
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=false;
                        }               
                    }
                    //加辣酱=酱+醋+糖+鸡蛋+辣酱
                    case "老板，最近想尝尝辣酱了~":{
                        if(IsBuyFlag1==false){
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=false;
                        }else{
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=false;
                        }               
                    }
                    case "老板，来一个豪华套餐！":{
                        if(IsBuyFlag4==false&&IsBuyFlag5==false){
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=false;
                        }else{
                            getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=true;
                            getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=false;
                            getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=false;
                        }               
                    }

                    default:{
                       // getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=true;
                       // getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=true;
                        break;
                    }
                }
                /*if(Order_Text=="我要一个加鸡柳烤冷面。"&&IsBuyFlag5==false){
                    console.log(IsBuyFlag5);
                    getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=true;
                    getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=true;

                }else if(Order_Text=="我要一个烤冷面加培根。"&&IsBuyFlag4==false){
                    console.log(IsBuyFlag4);
                    getGameObjectById('UI_dialog_cannotbuy_tip').getBehaviour(Display).IsActive=true;
                    getGameObjectById('UI_button_suanle').getBehaviour(Display).IsActive=true;
                }else{
                    getGameObjectById('UI_dialog_button_getIt').getBehaviour(Display).IsActive=true;
                    getGameObjectById('UI_dialog_button_what').getBehaviour(Display).IsActive=true;
                }*/

                
               

            }
        };
    }

    onTick(duringTime: number) {

    }

    SelectOrder(x:number){
        let order_detail:string;
        switch(x){
            case 1:{
                getGameObjectById('UI_dialog_requirement').getBehaviour(TextRenderer).text=this.Order1;
                this.Order_what=1;
                //getGameObjectById('UI_dialog_requirement_detail').getBehaviour(TextRenderer).text=this.Order1_what;
                break;
            }
            case 2:{
                getGameObjectById('UI_dialog_requirement').getBehaviour(TextRenderer).text=this.Order2;
                this.Order_what=2;
                //getGameObjectById('UI_dialog_requirement_detail').getBehaviour(TextRenderer).text=this.Order2_what;
                break;
            }
            case 3:{
                getGameObjectById('UI_dialog_requirement').getBehaviour(TextRenderer).text=this.Order3;
                this.Order_what=3;
               // getGameObjectById('UI_dialog_requirement_detail').getBehaviour(TextRenderer).text=this.Order3_what;
                break;
            }
            case 4:{
                getGameObjectById('UI_dialog_requirement').getBehaviour(TextRenderer).text=this.Order4;
                this.Order_what=4;
               // getGameObjectById('UI_dialog_requirement_detail').getBehaviour(TextRenderer).text=this.Order4_what;
                break;
            }
            case 5:{
                getGameObjectById('UI_dialog_requirement').getBehaviour(TextRenderer).text=this.Order5;
                this.Order_what=5;
                //getGameObjectById('UI_dialog_requirement_detail').getBehaviour(TextRenderer).text=this.Order5_what;
                break;
            }
            case 6:{
                getGameObjectById('UI_dialog_requirement').getBehaviour(TextRenderer).text=this.Order6;
                this.Order_what=5;
                //getGameObjectById('UI_dialog_requirement_detail').getBehaviour(TextRenderer).text=this.Order5_what;
                break;
            }
            case 7:{
                getGameObjectById('UI_dialog_requirement').getBehaviour(TextRenderer).text=this.Order7;
                this.Order_what=5;
                //getGameObjectById('UI_dialog_requirement_detail').getBehaviour(TextRenderer).text=this.Order5_what;
                break;
            }
            case 8:{
                getGameObjectById('UI_dialog_requirement').getBehaviour(TextRenderer).text=this.Order8;
                this.Order_what=5;
                //getGameObjectById('UI_dialog_requirement_detail').getBehaviour(TextRenderer).text=this.Order5_what;
                break;
            }
            case 9:{
                getGameObjectById('UI_dialog_requirement').getBehaviour(TextRenderer).text=this.Order9;
                this.Order_what=5;
                //getGameObjectById('UI_dialog_requirement_detail').getBehaviour(TextRenderer).text=this.Order5_what;
                break;
            }
            case 10:{
                getGameObjectById('UI_dialog_requirement').getBehaviour(TextRenderer).text=this.Order10;
                this.Order_what=5;
                //getGameObjectById('UI_dialog_requirement_detail').getBehaviour(TextRenderer).text=this.Order5_what;
                break;
            }
            default:{
                break;
            }
        }
    }

    GetRandomNum(Min:number,Max:number){
        let Range=Max-Min;
        let Rand=Math.random();
        return (Min+Math.round(Range*Rand));
    }

}
